package com.fsd.experiment3;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.OnClick;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    @OnClick(R.id.btn_butterKnifeBind)
    public void butterKnifeClick(){
        final TextView textView = findViewById(R.id.textMain);
        textView.setText("点击了【ButterKnife绑定】的监听器");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);//绑定ButterKnife

        Button btnInerClass = findViewById(R.id.btn_inerClass);
        btnInerClass.setOnClickListener(new InerClass());

        Button btnNoNameInerClass = findViewById(R.id.btn_noNameInerClass);//匿名内部类
        final TextView textView = findViewById(R.id.textMain);
        btnNoNameInerClass.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textView.setText("点击了采用【匿名内部类】的监听器");
            }
        });

        Button btnOutClass = findViewById(R.id.btn_outClass);//外部类
        btnOutClass.setOnClickListener(new outClass(textView));

        Button btnActivityLisener = findViewById(R.id.btn_activityLisener);//Activity本身
        btnActivityLisener.setOnClickListener(this);

        Button btn_Information = findViewById(R.id.btn_infomation);
        btn_Information.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, InformationActivity.class);
                startActivity(intent);
            }
        });

        Button btn_ProgressBar = findViewById(R.id.btn_progressBar);
        btn_ProgressBar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ProgressBarActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void onClick(View v) {
        final TextView textView = findViewById(R.id.textMain);
        textView.setText("点击了采用【Activity】的监听器");
    }

    class InerClass implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            final TextView textView = findViewById(R.id.textMain);
            textView.setText("点击了采用【内部类】的监听器");
        }
    }

    public void clickHander(View source){
        final TextView textView = findViewById(R.id.textMain);
        textView.setText("点击了采用【绑定到标签】的监听器");
    }
}


class outClass implements View.OnClickListener {//外部类实现
    private TextView textView;
    outClass(TextView textView){
        this.textView = textView;
    }

    @Override
    public void onClick(View v) {
        textView.setText("点击了采用【外部类】的监听器");
    }
}
